clear
cd "...\FirmLevelData"
use ASI_Processed_PanelData_FirmLevel_AllYears_20250115
gen fill_miss=0.01
destring *, replace
gen ln_Capital_Labour_Ratio_Const =log( Capital_Labour_Ratio_Const )
drop if ln_Capital_Labour_Ratio_Const == .
gen ln_Labour_Prod_Const =log( Labour_Prod_Const )
replace ln_Labour_Prod_Const=fill_miss if ln_Labour_Prod_Const==.
encode Size_Class, gen(Size_Class_Code)
encode Use_Base_Class, gen(Use_Base_Class_Code)

cd "...\Analysis"

****************************************************************

preserve

tabstat Alt_Profit_Rate , statistics(min p1 p5 p95 p99 max)
_pctile Alt_Profit_Rate, p(1, 99)
keep if Alt_Profit_Rate>=  r(r1) & Alt_Profit_Rate<= r(r2)

sort Proxy_Fact_ID Fin_Year
xtset Proxy_Fact_ID Fin_Year

xtreg Alt_Profit_Rate Large_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe

estimate store fe

xtreg Alt_Profit_Rate Large_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, re
estimate store re

hausman fe re, sigmamore

eststo : xtreg Alt_Profit_Rate Small_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Alt_Profit_Rate Med_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Alt_Profit_Rate Large_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Alt_Profit_Rate Small_Incidence Med_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Alt_Profit_Rate Small_Incidence Med_Incidence Age l.NVA_Conc_Sq l.ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

esttab using ROPREG_PANEL_SMALL_MEDIUM_LARGE.csv, replace title("ROPREG PANEL SMALL MEDIUM LARGE") cells(b(fmt(%9.3f) star) se(par)) stats( N r2, fmt(%9.2f %9.0g)labels( Observations R2)) label style(tex) legend modelwidth(8) noconstant nogaps nonumbers nodepvars mtitles ("SMALL" "MEDIUM" "LARGE" "SMALL MEDIUM" "SMALL MEDIUM LAG") 
eststo dir
eststo clear

restore

****************************************************************

preserve

tabstat Input_Output_Ratio_Const , statistics(min p1 p5 p95 p99 max)
_pctile Input_Output_Ratio_Const, p(1, 99)
keep if Input_Output_Ratio_Const>=  r(r1) & Input_Output_Ratio_Const<= r(r2)

sort Proxy_Fact_ID Fin_Year
xtset Proxy_Fact_ID Fin_Year

eststo : xtreg Input_Output_Ratio_Const Small_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Input_Output_Ratio_Const Med_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Input_Output_Ratio_Const Large_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Input_Output_Ratio_Const Small_Incidence Med_Incidence Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Input_Output_Ratio_Const Small_Incidence Med_Incidence Age l.NVA_Conc_Sq l.ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

esttab using IOREG_PANEL_SMALL_MEDIUM_LARGE.csv, replace title("IOREG PANEL SMALL MEDIUM LARGE") cells(b(fmt(%9.3f) star) se(par)) stats( N r2, fmt(%9.2f %9.0g)labels( Observations R2)) label style(tex) legend modelwidth(8) noconstant nogaps nonumbers nodepvars mtitles ("SMALL" "MEDIUM" "LARGE" "SMALL MEDIUM" "SMALL MEDIUM LAG")   
eststo dir
eststo clear

restore

****************************************************************
preserve

tabstat Input_Output_Ratio_Const , statistics(min p1 p5 p95 p99 max)
_pctile Input_Output_Ratio_Const, p(1, 99)
keep if Input_Output_Ratio_Const>=  r(r1) & Input_Output_Ratio_Const<= r(r2)

sort Proxy_Fact_ID Fin_Year
xtset Proxy_Fact_ID Fin_Year

eststo : xtreg Input_Output_Ratio_Const Large_Incidence##i.Use_Base_Class_Code Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Input_Output_Ratio_Const Large_Incidence##i.Use_Base_Class_Code Age l.NVA_Conc_Sq l.ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Alt_Profit_Rate Large_Incidence##i.Use_Base_Class_Code Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Alt_Profit_Rate Large_Incidence##i.Use_Base_Class_Code Age l.NVA_Conc_Sq l.ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

esttab using IOREG_PANEL_LARGE_INTERACTIONS.csv, replace title("PANEL LARGE INTERACTIONS") cells(b(fmt(%9.3f) star) se(par)) stats( N r2, fmt(%9.2f %9.0g)labels( Observations R2)) label style(tex) legend modelwidth(8) noconstant nogaps nonumbers nodepvars mtitles ("LARGE USECLASS IO" "LARGE USECLASS IO LAG" "LARGE USECLASS ROP" "LARGE USECLASS ROP LAG")   
eststo dir
eststo clear

restore


****************************************************************

preserve

tabstat Alt_Profit_Rate , statistics(min p1 p5 p95 p99 max)
_pctile Alt_Profit_Rate, p(1, 99)
keep if Alt_Profit_Rate>=  r(r1) & Alt_Profit_Rate<= r(r2)

sort Proxy_Fact_ID Fin_Year
xtset Proxy_Fact_ID Fin_Year

gen Large_Managerial_Interact = Large_Incidence*Managerial_Wage_Share
gen Large_RandD_Interact = Large_Incidence*RandD_Intensity

eststo : xtreg Alt_Profit_Rate Large_Incidence Large_Managerial_Interact Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

eststo : xtreg Alt_Profit_Rate Large_Incidence Large_Managerial_Interact Large_RandD_Interact Age NVA_Conc_Sq ln_Labour_Prod_Const ln_Capital_Labour_Ratio_Const Import_Firm_Incidence Org_Class Rental_Share_Const NVA_Const_Growth_Indus_State, fe vce(robust)

esttab using ROPREG_PANEL_LARGE_MANAGERIAL.csv, replace title("ROPREG PANEL LARGE MANAGERIAL") cells(b(fmt(%9.3f) star) se(par)) stats( N r2, fmt(%9.2f %9.0g)labels( Observations R2)) label style(tex) legend modelwidth(8) noconstant nogaps nonumbers nodepvars mtitles ("LARGE MANAGERIAL" "LARGE MANAGERIAL RD")   
eststo dir
eststo clear

restore

****************************************************************
***************************************************************
clear
import delimited "...\io_reg_data_allvars_1.csv"
cd "...\Analysis"

keep if size_class!="0_ALL" & size_class!="4_MI"
drop if (nva_multi ==0 | emp_workers_multi==0 | capstock_pim_constprice<=0 | total_output_multi==0)

destring input_output_ratio_const labour_prod_const capital_prod_const capital_nva_ratio_const capital_labour_ratio_const rental_share_const, replace

drop if state_code==0 | nic_3dig == 0

***************************************************
preserve

tabstat input_output_ratio_const , statistics(min p1 p5 p95 p99 max)
_pctile input_output_ratio_const, p(1, 99)
keep if input_output_ratio_const>=  r(r1) & input_output_ratio_const<= r(r2)

bysort state_code nic_3dig size_class: gen state_nic_freq = _N
drop if state_nic_freq<21

gen panelvar=string(state_code ,"%02.0f")+string(nic_3dig ,"%02.0f")+size_class
encode panelvar , gen(pvar)
xtset pvar fin_year

sort pvar fin_year

gen ln_Capital_Labour_Ratio_Const =log( capital_labour_ratio_const )
gen ln_Labour_Prod_Const =log( labour_prod_const )
gen fill_miss=0.01
replace ln_Labour_Prod_Const=fill_miss if ln_Labour_Prod_Const==.
replace ln_Capital_Labour_Ratio_Const=fill_miss if ln_Capital_Labour_Ratio_Const==.

*xtunitroot fisher ln_Capital_Labour_Ratio_Const , dfuller lags(1)

eststo : xtreg input_output_ratio_const small_incidence psu_incidence import_firm_incidence rental_share_const ln_Capital_Labour_Ratio_Const ln_Labour_Prod_Const nva_const_growth_statelevel, fe robust

eststo : xtreg input_output_ratio_const medium_incidence psu_incidence import_firm_incidence rental_share_const ln_Capital_Labour_Ratio_Const ln_Labour_Prod_Const nva_const_growth_statelevel, fe robust

eststo : xtreg input_output_ratio_const large_incidence psu_incidence import_firm_incidence rental_share_const ln_Capital_Labour_Ratio_Const ln_Labour_Prod_Const nva_const_growth_statelevel, fe robust

eststo : xtreg input_output_ratio_const small_incidence medium_incidence psu_incidence import_firm_incidence rental_share_const ln_Capital_Labour_Ratio_Const ln_Labour_Prod_Const nva_const_growth_statelevel, fe robust

esttab using IOREG_SIZECLASSWISE_SMALL_MEDIUM_LARGE.csv, replace title("IOREG SIZECLASSWISE SMALL MEDIUM LARGE") cells(b(fmt(%9.3f) star) se(par)) stats( N r2, fmt(%9.2f %9.0g)labels( Observations R2)) label style(tex) legend modelwidth(8) noconstant nogaps nonumbers nodepvars mtitles ("SMALL" "MEDIUM" "LARGE" "SMALL MEDIUM")   
eststo dir
eststo clear

restore

***************************************************
preserve

tabstat alt_profit_rate , statistics(min p1 p5 p95 p99 max)
_pctile alt_profit_rate, p(1, 99)
keep if alt_profit_rate>=  r(r1) & alt_profit_rate<= r(r2)

bysort state_code nic_3dig size_class: gen state_nic_freq = _N
drop if state_nic_freq<21

gen panelvar=string(state_code ,"%02.0f")+string(nic_3dig ,"%02.0f")+size_class
encode panelvar , gen(pvar)
xtset pvar fin_year

sort pvar fin_year

gen ln_Capital_Labour_Ratio_Const =log( capital_labour_ratio_const )
gen ln_Labour_Prod_Const =log( labour_prod_const )
gen fill_miss=0.01
replace ln_Labour_Prod_Const=fill_miss if ln_Labour_Prod_Const==.
replace ln_Capital_Labour_Ratio_Const=fill_miss if ln_Capital_Labour_Ratio_Const==.

*xtunitroot fisher ln_Capital_Labour_Ratio_Const , dfuller lags(1)

eststo : xtreg alt_profit_rate small_incidence psu_incidence import_firm_incidence rental_share_const ln_Capital_Labour_Ratio_Const ln_Labour_Prod_Const nva_const_growth_statelevel, fe robust

eststo : xtreg alt_profit_rate medium_incidence psu_incidence import_firm_incidence rental_share_const ln_Capital_Labour_Ratio_Const ln_Labour_Prod_Const nva_const_growth_statelevel, fe robust

eststo : xtreg alt_profit_rate large_incidence psu_incidence import_firm_incidence rental_share_const ln_Capital_Labour_Ratio_Const ln_Labour_Prod_Const nva_const_growth_statelevel, fe robust

eststo : xtreg alt_profit_rate small_incidence medium_incidence psu_incidence import_firm_incidence rental_share_const ln_Capital_Labour_Ratio_Const ln_Labour_Prod_Const nva_const_growth_statelevel, fe robust

esttab using ROPREG_SIZECLASSWISE_SMALL_MEDIUM_LARGE.csv, replace title("ROPREG SIZECLASSWISE SMALL MEDIUM LARGE") cells(b(fmt(%9.3f) star) se(par)) stats( N r2, fmt(%9.2f %9.0g)labels( Observations R2)) label style(tex) legend modelwidth(8) noconstant nogaps nonumbers nodepvars mtitles ("SMALL" "MEDIUM" "LARGE" "SMALL MEDIUM")   
eststo dir
eststo clear

restore

***************************************************

